const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const distPath = path.resolve(process.cwd(), 'dist');
let config = {
    mode: 'development',
    entry: ['./src/build/entry.js'],
    output: {
        filename: 'js/[name].[chunkhash:8].js',
        path: distPath,
        clean: true,
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: "./project/index.html",
            hash: true
        })
    ],
    module: {
        rules: [
            {
                test: /\.less$/i,
                include: /src/,
                use: [
                    { loader: 'style-loader' },
                    { loader: 'css-loader' },
                    { loader: 'less-loader' },
                ]
            }, {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: {
                            cacheDirectory: true
                        }
                    }
                ],
                resolve: {
                    extensions: ['.js', '.jsx'],
                }
            }

        ]
    },
    resolve: {
        alias: {
            '@root': path.resolve(__dirname, '../src')
        },
        extensions: ['.js', '.jsx', '.less'],
    }
};
module.exports = config;